#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QFile>
#include <QMessageBox>
#include <QTextCodec>
#include <QLibrary>
#include <QtSql/QtSql>
#include <articlestruct.h>
#include "dialog.h"
#include "loaddialog.h"
#include <docstruct.h>
#include "structs.h"
#include "workdll.h"
#include <stoplist.h>
#include <QListWidgetItem>
#include "mdialog.h"

typedef QVector<QString> SList;
typedef QList<float> vect;

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

typedef bool (*TdbConnect)(QString);
typedef void (*TgetModel)(QSqlTableModel*, QString);
typedef bool (*TdbInsert)(ArticleStruct);
typedef QList<ArticleStruct> (*TfromFile)(QString fileName);
typedef void (*TtoFile)(QList<ArticleStruct>, QString fileName);
typedef void (*TsetFile)(QString);
typedef QList<SList> (*TmodelToList)(QSqlTableModel*);
typedef bool (*Tmethod)(QList<Doc> &Docs,
                        QVector<double> Params,
                        QVector<QVector<double> >& Result);
typedef bool (*Tparams)(QList<Parameters> &Params);

private:
    Ui::MainWindow *ui;

private:
    void initDll();
    void initMethods();


private slots:
    void sDBOpen();
    void sCalc();
    void sChooseMethod();
    void sSaveToFile();
    void sFilt();
    void sStopLoad();
    void sCheckStop();
    void sFromFile();
    void sFromSite();
    void sBySelf();
    void sDBView(QModelIndex ind);
    void sResultView(QListWidgetItem* item);

    void on_btnCount_clicked();

private:
    TdbConnect dbConnect;
    TgetModel getModel;
    TdbInsert dbInsert;
    TfromFile fromFile;
    TtoFile toFile;
    TsetFile setFileName;
    TmodelToList modelToList;
    Tmethod shingle;
    Tparams shingleParams;
    stopList* stopL;

    bool isConnected;
    QString sqlParams;


    QString md5Hash(QString str)
    {
        QCryptographicHash md5(QCryptographicHash::Md5);
        md5.addData(str.toAscii());
        return md5.result().toHex().constData();
    }

    int Min( const int x, const int y )
    {
       return ( x > y ) ? y : x;
    }


};

#endif // MAINWINDOW_H
